package oo.day06;

import java.util.Scanner;

public class UnionPayTest {

	public static void main(String[] args) {

		Union card1 = new ICBCImpl(1000, "123456");
		Union card2 = new ABCImpl(2000, "123456");
		Union card3 = new CCBImpl(3000, "123456");
		atm(card2);

	}

	public static void atm(Union card) {
		Scanner scan = new Scanner(System.in);
		ABCATM ABCatm = new ABCATM();
		int diffBank = ABCatm.insertCard(card);
		System.out.println("请输入密码");
		while (true) {
			String pwd = scan.next();
			if (card.checkPwd(pwd)) {
				System.out.println("请输入要办理的业务:1.查询余额;2存钱;3取钱;4农行卡可以充话费;0退出");
				int select = scan.nextInt();
				switch (select) {
				case 1:
					double selectNum = card.selectMoney();
					System.out.println("余额:" + selectNum);
					break;
				case 2:
					System.out.println("请输入存款金额:");
					int saveNum = scan.nextInt();
					if (card.saveMoney(saveNum)) {
						System.out.println("存款成功");
					} else {
						System.out.println("存款失败");
					}
					break;
				case 3:
					System.out.println("请输入取款金额:");
					int getNum = scan.nextInt();
					if (card.getMoney(getNum)) {
						System.out.println("取款成功");
					} else {
						System.out.println("取款失败");
					}
					break;
				case 4:
					if (card.diffBank() == 2) {
						System.out.println("话费充值成功");
					} else {
						System.out.println("只有农行卡可以充值话费");
					}
					break;
				default:
					return;
				}
			} else {
				System.out.println("密码错误，请重新输入");

			}
		}
	}

}
//创建ATM机，插卡。返回值决定是哪家银行的银行卡
class ABCATM {
	public int insertCard(Union card) {
		return card.diffBank();
	}
}
//创建银联接口，建立银行卡基本功能，存、取、查询、检查密码、决定是哪家银行的卡
interface Union {
	public boolean saveMoney(double num);

	public boolean getMoney(double num);

	public double selectMoney();

	public boolean checkPwd(String pwd);

	// 1.工商银行 2.农业银行 3.建行
	public int diffBank();

}
//工商银行独有线上支付功能
interface ICBC extends Union {
	abstract void payOnline(double num);
}
//农业银行独有充话费功能
interface ABC extends Union {
	abstract void payPhoneBill(double num, String telNumber);
}
//建行独有交水费功能
interface CCB extends Union {
	abstract void payWaterBill(double num, String AddressNumber);
}
//构建银行抽象类，用来区分哪家银行的银行卡， 实现银联共有方法
abstract class bank implements Union {
	//余额和密码是银行共有的
	protected double balance;
	protected String pwd;
	//区分是哪家银行
	abstract public int diffBank();
	//普通方法 存 取  查  检查密码
	public boolean saveMoney(double num) {
		this.balance += num;
		return true;
	}

	public boolean getMoney(double num) {
		if (balance >= num) {
			balance -= num;
			return true;
		}
		return false;
	}

	public double selectMoney() {
		return balance;
	}

	public boolean checkPwd(String pwd) {
		if (pwd.equals(this.pwd)) {
			return true;
		}
		return false;
	}
}
//银行卡继承银行特性
class ICBCImpl extends bank {

	ICBCImpl(double money, String pwd) {
		this.balance = money;
		this.pwd = pwd;
	}

	public int diffBank() {
		return 1;
	}

	void payOnline(double num) {

	}
}

class ABCImpl extends bank {

	ABCImpl(double money, String pwd) {
		this.balance = money;
		this.pwd = pwd;
	}

	public int diffBank() {
		return 2;
	}

	void payPhoneBill(double num, String telNumbner) {

	}
}

class CCBImpl extends bank {

	CCBImpl(double money, String pwd) {
		this.balance = money;
		this.pwd = pwd;
	}

	public int diffBank() {
		return 3;
	}

	void payWaterBill(double num, String AddressNumber) {

	}
}
